<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\Users;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redis;


class AuthController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
    }
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    /**
     * authenticate 登录认证
     * 
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function authenticate(Request $request)
    {
//        $request->session()->put('hna_src_user_login_info', 11);
        Redis::set('hna_src_user_login_info',333);
        //登录成功写入用户信息
        return true;
    }

    /**
     * register 注册用户生成token
     * 
     * @param Request $request
     * @return mixed
     */
/*    public function register(Request $request)
    {
        $newUser = [
            'email' => $request->get('email'),
            'name' => $request->get('name'),
            'password' => bcrypt($request->get('password'))
        ];

        $user = Users::create($newUser);
        return $user;
    }*/

    /**
     * AuthenticatedUser 获取用户的信息
     * 
     * @return \Illuminate\Http\JsonResponse
     */
    public function AuthenticatedUser()
    {
/*        try {
            if (!$user = JWTAuth::parseToken()->authenticate()) {
                return response()->json(['user_not_found'], 404);
            }
        } catch (TokenExpiredException $e) {
            return response()->json(['token_expired'], $e->getStatusCode());
        } catch (TokenInvalidException $e) {
            return response()->json(['token_invalid'], $e->getStatusCode());
        } catch (JWTException $e) {
            return response()->json(['token_absent'], $e->getStatusCode());
        }*/
        return response()->json(compact('user'));
    }
}
